import {queryCountReport } from '../services/report';

export default {
    namespace: 'distributeCountReport',

    state: {
        data: {
            list: [],
            pagination: {},
        },
        loading: true,
    },
    effects: {
        * fetch({payload, callback}, {call, put}) {
            yield put({
                type: 'changeLoading',
                payload: true,
            });
            const response = yield call(queryCountReport, payload);
            yield put({
                type: 'save',
                payload: response,
            });
            yield put({
                type: 'changeLoading',
                payload: false,
            });
            if (callback) callback(response);
        },
    },

    reducers: {
        save(state, action) {
            return {
                ...state,
                data: action.payload.resultData.distributeCountReport,
            };
        },


        changeLoading(state, action) {
            return {
                ...state,
                loading: action.payload,
            };
        },
    },

};
